import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 引入多个动态路由模块
import approvalsRouter from './modules/approvals'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import permissionRouter from './modules/permission'
import attendancesRouter from './modules/attendances'
import salarysRouter from './modules/salarys'
import settingRouter from './modules/setting'
import socialRouter from './modules/social'

// 静态路由表, 项目中所有的用户都可以访问的功能
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout, // 布局容器，帮助我们生成了主要的结构
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/excel',
    component: Layout,
    children: [{
      path: '',
      name: 'Excel',
      component: () => import('@/views/excel'),
      hidden: true
    }]
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

// 动态路由表，项目中不同的用户可以访问不同的功能
export const asyncRoutes = [
  departmentsRouter, // 组织架构 （departments）：公司的人员架构
  settingRouter, // 角色管理 （settings）：角色管理
  employeesRouter, // 员工管理（employees）：给员工分配角色
  permissionRouter, // 权限管理（permission）：配置各种权限点
  approvalsRouter, // 本期不实现功能
  attendancesRouter, // 本期不实现功能
  salarysRouter, // 本期不实现功能
  socialRouter // 本期不实现功能
]

// 对路由进行实例化
const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 挂载路由规则
  // routes: [...constantRoutes, ...asyncRoutes]
  routes: [...constantRoutes]

})

const router = createRouter()

// 进行路由重置
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
